package com.unionftech.common.webview

import android.webkit.WebSettings
import com.unionftech.common.webview.view.BaseWebView

class WebViewDefaultSetting private constructor() {
    companion object {
        @Volatile
        private var instance: WebViewDefaultSetting? = null

        @JvmStatic
        fun getInstance() = instance ?: synchronized(this) {
            instance ?: WebViewDefaultSetting().also {
                instance = it
            }
        }
    }

    fun toSetting(webView: BaseWebView) {
        webView.isHorizontalScrollBarEnabled = false
        webView.isVerticalScrollBarEnabled = false
        //允许截图
        webView.isDrawingCacheEnabled = true
        //屏蔽长按事件
        webView.setOnLongClickListener {
            return@setOnLongClickListener true
        }
        //初始化WebSettings
        val settings = webView.settings
        settings.javaScriptEnabled = true
        val ua = settings.userAgentString
        settings.userAgentString = ua + "Latte"
        settings.builtInZoomControls = false
        settings.displayZoomControls = false
        settings.setSupportZoom(false)
        settings.allowFileAccess = true
        settings.allowFileAccessFromFileURLs = true
        settings.allowUniversalAccessFromFileURLs = true
        settings.allowContentAccess = true

        settings.domStorageEnabled = true
        settings.databaseEnabled = true
        settings.cacheMode = WebSettings.LOAD_DEFAULT
    }

}
